/**
 * 
 */
package com.cloudcast.client.controller;

import java.util.Map;

import com.cloudcast.client.presenter.DashboardMainPresenter;
import com.cloudcast.client.presenter.DashboardMenuPresenter;
import com.cloudcast.client.presenter.Presenter;
import com.cloudcast.client.presenter.SimplePresenter;
import com.cloudcast.client.view.DashboardView;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.google.gwt.event.shared.HandlerManager;

/**
 * @author Samuel García Martínez <in0de>
 *
 */
public class DashboardController extends MultiPresenterController {
	
	private static final String TOKEN_DASHBOARD_MAIN = "dashboard";
	private static final String TOKEN_DASHBOARD_MENU = "dashboard-menu";
	
	private static final String ID = "Dashboard.Controller";
	
	private Presenter dashboardPresenter;
	private DashboardView view;
	
	public DashboardController(Controller parent, HandlerManager eventBus) {
		super(parent, eventBus);
	}
	
	/* (non-Javadoc)
	 * @see com.cloudcast.client.controller.MultiPanelController#registerContainers(java.util.Map)
	 */
	@Override
	public void registerContainers(Map<String, LayoutContainer> containers) {
		containers.put(TOKEN_DASHBOARD_MENU, getView().getMenuPanel());
		containers.put(TOKEN_DASHBOARD_MAIN, getView().getMainPanel());
	}

	/* (non-Javadoc)
	 * @see com.cloudcast.client.controller.AbstractController#registerResponsibles(java.util.Map)
	 */
	@Override
	protected void registerResponsibles(Map<String, Responsible> responsibles) {
		responsibles.put(TOKEN_DASHBOARD_MAIN, new DashboardMainPresenter(this, this.getEventBus()));
		responsibles.put(TOKEN_DASHBOARD_MENU, new DashboardMenuPresenter(this, this.getEventBus()));
	}	

	/* (non-Javadoc)
	 * @see com.cloudcast.client.controller.Responsible#getContainer()
	 */
	@Override
	public LayoutContainer getContainer() {
		return getView().asContainer();
	}

	/* (non-Javadoc)
	 * @see com.cloudcast.client.controller.Responsible#getId()
	 */
	@Override
	public String getId() {
		return ID;
	}

	/* (non-Javadoc)
	 * @see com.cloudcast.client.controller.Responsible#unbind(com.cloudcast.client.controller.Controller)
	 */
	@Override
	public void unbind(Controller controller) {
		// TODO Auto-generated method stub
	}
	
	private DashboardView getView() {
		if(this.view == null) 
			this.view = new DashboardView();
		
		return this.view;
	}

	@Override
	public Presenter getPresenter() {
		if(this.dashboardPresenter == null)
			this.dashboardPresenter = new SimplePresenter(this, 
						getEventBus(), getView(), "Dashboard.View");

		return this.dashboardPresenter;
	}

	@Override
	protected void doBind(Controller controller) {
	}

}
